package com.cx.controller;

import com.cx.common.ApiReturn;
import com.cx.pojo.Base;
import com.cx.service.BaseService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("base")
public class BaseController {

    @Autowired
    BaseService baseService;

    //添加汽车基本参数
    @RequestMapping("insertBase")
    @ResponseBody
    public ApiReturn insertBase(Base base){
        int rows = baseService.insert(base);
        if (rows<1){
            return ApiReturn.error("添加失败");
        }
        return  ApiReturn.success("添加成功");
    }

    //修改汽车基本参数
    @RequestMapping("updateBase")
    @ResponseBody
    public ApiReturn updateBase(Base base){
        int rows = baseService.updateByPrimaryKey(base);
        if (rows<1){
            return ApiReturn.error("修改失败");
        }
        return ApiReturn.success("修改成功");
    }

    //删除汽车基本参数
    @RequestMapping("deleteBase")
    @ResponseBody
    public ApiReturn deleteBase(Integer baseId) {
        int rows = baseService.deleteByPrimaryKey(baseId);
        if (rows < 1) {
            return ApiReturn.error("删除失败");
        }
        return ApiReturn.success("删除成功");
    }

    //根据id查询汽车基本参数
    @RequestMapping("selectBaseById")
    @ResponseBody
    public ApiReturn selectEngineById(Integer baseId) {
        Base baseInfo = baseService.selectByPrimaryKey(baseId);
        if (baseInfo != null) {
            return ApiReturn.success("汽车基本数据详情",baseInfo);
        }
        return ApiReturn.error("未获取该汽车基本数据详情");
    }

    //查询所有汽车基本参数
    @RequestMapping("selectAllBase")
    @ResponseBody
    public ApiReturn selectAllBase(Base base) {
        PageInfo<Base> page = baseService.selectAllBase(base);
        if (page.getList() != null) {
            return ApiReturn.success("所有汽车基本数据",page);
        }
        return ApiReturn.error("无数据");
    }
}
